package com.itheima.mapper;

import com.itheima.pojo.CheckItem;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface CheckItemMapper {
    /**
     * 新增检查项
     * @param checkItem
     */
    @Insert("insert into check_item(code,name,sex,age,price,remark,attention,type) " +
            "values(#{code},#{name},#{sex},#{age},#{price},#{remark},#{attention},#{type})")
    Integer insert(CheckItem checkItem);

    /**
     * 检查检查项是否在关系表中
     * @param checkItemId
     * @return
     */
    @Select("select check_group_id from check_group_check_item where check_item_id=#{checkItemId}")
    List<Integer> findGroupIdsByCheckItemId(Integer checkItemId);

    /**
     * 根据检查项id删除检查项
     * @param id
     */
    @Delete("delete from check_item where id=#{id}")
    void deleteById(Integer id);

    /**
     * 修改检查项
     * @param checkItem
     */
    Integer edit(CheckItem checkItem);

    /**
     * 条件查询
     * @param queryString
     * @return
     */
    List<CheckItem> findPageByQueryString(String queryString);

    /**
     * 查询所有
     * @return
     */
    @Select("select * from check_item")
    List<CheckItem> findAll();

    /**
     * 根据id查询检查项
     * @param id
     * @return
     */
    @Select("select * from check_item where id=#{id}")
    CheckItem findById(Integer id);
}
